<?php
class ArrayComponent extends CComponent
{
    public static function array_column($array, $column_key, $index_key = null)
    {
        $result = array();
        foreach ($array as $key => $value) {
            if (is_null($index_key)) {
                $result[] = $value[$column_key];
            } else {
                $result[$value[$index_key]] = $value[$column_key];
            }
        }
        return $result;
    }

    public static function array_part($array, $column_key)
    {
        $result = array();
        $column_key = is_array($column_key) ? $column_key : array($column_key);
        foreach ($array as $key => $value) {
            if (in_array($key, $column_key)) {
                $result[$key] = $value;
            }
        }
        return $result;
    }

   /**
     * 递归将数组中所有 null 替换成 ''
     * @return arr
     * @author 
     */
 public static function unsetNullArr($arr)
    {

        $narr = array();
        while(list($key, $val) = each($arr)){
            if (is_array($val)){
                $val = ArrayComponent::unsetNullArr($val);
                count($val)==0 || $narr[$key] = $val;
            }else{
                $val === null?$narr[$key] = '':$narr[$key] = $val;
            }
        }
        return $narr;
    }
}
